package com.guanghua.brick.html.fileupload;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CommonFileUpload implements IFileUpload {
	
	private static Log logger = LogFactory.getLog(CommonFileUpload.class);
	private static int index = 0;

	public String downloadFile(Long fileId, OutputStream os) throws Exception {
		os.write("text.uploader".getBytes());
		return "中国.xxx.rar";
	}

	public List<Map<String, String>> listUploadFile(Long objectId)
			throws Exception {
		logger.info("object id:" + objectId);
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		Map<String, String> map = new HashMap<String, String>();
		map.put("value", "1");
		map.put("text", "a.xml");
		list.add(map);
		return list;
	}

	public List<Map<String, String>> listUploadFile(Long objectId,
			Long objectType) throws Exception {
		logger.info("object id:" + objectId);
		logger.info("object tp:" + objectType);
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		Map<String, String> map = new HashMap<String, String>();
		map.put("value", "1");
		map.put("text", "a.xml");
		list.add(map);
		return list;
	}

	public void removeUploadFile(Long fileId) throws Exception {
		logger.info("file id:" + fileId);
	}

	public Long uploadFile(Long objectId, Long objectType, InputStream is,
			String fileName) throws Exception {
		logger.info("object id:" + objectId);
		logger.info("object tp:" + objectType);
		logger.info("file name:" + fileName);
		logger.info("file content:" + is);
		return new Long(index++);
	}

	public Long uploadFile(Long objectId, InputStream is, String fileName)
			throws Exception {
		logger.info("object id:" + objectId);
		logger.info("file name:" + fileName);
		logger.info("file content:" + is);
		return new Long(index++);
	}
	
	public Long uploadFile(InputStream is, String fileName)
			throws Exception {
		logger.info("file name:" + fileName);
		logger.info("file content:" + is);
		return new Long(index++);
	}

}
